<html>
  <head>
    <script type="application/javascript">
      function draw() {
        var canvas = document.getElementById("canvas");
        var ctx = canvas.getContext("2d");
        var img = new Image();
        img.onload = () => {
          // 加载完执行
          ctx.drawImage(img, 0, 0, 64, 32, 0, 0, 128, 64);
        };
        img.src = "https://www.baidu.com/favicon.ico";
      }
    </script>
  </head>
  <body onload="draw();">
    <canvas id="canvas" width="300" height="300"></canvas>
  </body>
</html>
<style>
  #canvas {
    background-color: aqua;
  }
</style>
